﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using CVSA.Suporte.Sinacor.BMFBovespa.Negocio;
using CVSA.Suporte.Sinacor.BMFBovespa.Entidades;

namespace CVSA.Suporte.Sinacor.BMFBovespa.ConsultaRemedy.Common
{
    public class AppCache
    {
        private Remedy remedy = new Remedy();
        private Negocio.SRM srm = new Negocio.SRM();

        public DataTable Tb_ChamadosFechados()
        {
            DataTable odt = new DataTable();

            if (System.Web.HttpContext.Current.Cache["cacheChamadosFechados"] != null)
            {
                odt = (DataTable)System.Web.HttpContext.Current.Cache["cacheChamadosFechados"];
            }
            else
            {
                odt=  remedy.ObterChamadosFechados();
                System.Web.HttpContext.Current.Cache.Add("cacheChamadosFechados", odt, null, System.Web.Caching.Cache.NoAbsoluteExpiration , new TimeSpan(0, 0, 5, 0), System.Web.Caching.CacheItemPriority.High, null);
            }

            return odt;
        }

        public DataTable  Tb_ChamadosAbertos()
        {

            DataTable odt = new DataTable();

            //if (System.Web.HttpContext.Current.Cache["cacheChamadosAbertos"] != null)
            //{
            //    odt = (DataTable)System.Web.HttpContext.Current.Cache["cacheChamadosAbertos"];
            //}
            //else
            //{
                odt = remedy.ObterChamadosAbertos();
            //    System.Web.HttpContext.Current.Cache.Add("cacheChamadosAbertos", odt, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 1, 0), System.Web.Caching.CacheItemPriority.High, null);
            //}

            return odt;
        }

        public DataTable Tb_Chamados(string clause)
        {
            DataTable odt = new DataTable();
            odt = remedy.ObterChamadosDB(clause);
            return odt;
        }

        public DataTable Tb_ChamadosAbertosSRM()
        {

            DataTable odt = new DataTable();
           
            odt = srm.ObterChamadosAbertos();
           
            return odt;
        }

        public DataTable Tb_ChamadosSRM(string clause)
        {
            DataTable odt = new DataTable();
            odt = srm.ObterChamadosDB(clause);
            return odt;
        }
        
        public DataTable Tb_PrioridadeChamados()
        {
            DataTable odt = new DataTable();

            if (System.Web.HttpContext.Current.Cache["cachePrioridadeChamados"] != null)
            {
                odt = (DataTable)System.Web.HttpContext.Current.Cache["cachePrioridadeChamados"];
            }
            else
            {
                odt = remedy.ObterPrioridadeChamados();
                System.Web.HttpContext.Current.Cache.Add("cachePrioridadeChamados", odt, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 0,1440, 0), System.Web.Caching.CacheItemPriority.High, null);
            }

            return odt;
        }

        public DataTable Tb_AreasChamado()
        {
            DataTable odt = new DataTable();

            if (System.Web.HttpContext.Current.Cache["cacheAreasChamados"] != null)
            {
                odt = (DataTable)System.Web.HttpContext.Current.Cache["cacheAreasChamados"];
            }
            else
            {
                odt = remedy.ObterAreasChamados();
                System.Web.HttpContext.Current.Cache.Add("cacheAreasChamados", odt, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 1440, 0), System.Web.Caching.CacheItemPriority.High, null);
            }

            return odt;
        }
    }
}
